/**
 * @author wangj881
 * @date 2024-12-12 18:00
 */
public class L226_2 {

    class Solution {
        public TreeNode invertTree(TreeNode root) {
            if (root == null) {
                return null;
            }
            invertTree(root.left);
            invertTree(root.right);
            swapChild(root);
            return root;
        }

        private void swapChild(TreeNode root) {
            TreeNode tmp = root.right;
            root.right = root.left;
            root.left = tmp;

        }
    }
}
